package hu.mapro.flang.gwt.war.client;

import hu.mapro.flang.gwt.client.request.ApplicationRequestFactory;
import hu.mapro.flang.gwt.client.ui.UiMessages;
import hu.mapro.flang.gwt.domain.client.AutoBeans.RequestFactory;
import hu.mapro.flang.gwt.domain.client.AutoBeans.UiBuilderMenuGroup;
import hu.mapro.gwt.data.shared.GwtDataRequestTransport;
import hu.mapro.gwtui.client.app.Menu;
import hu.mapro.gwtui.client.app.MenuGroup;
import hu.mapro.gwtui.client.app.UserDesktop;
import hu.mapro.gwtui.client.app.Workspace;
import hu.mapro.gwtui.gxt.client.GxtUserGinModule;

import javax.inject.Singleton;

import com.google.gwt.core.client.GWT;
import com.google.inject.Provides;
import com.google.web.bindery.event.shared.SimpleEventBus;

public class ApplicationGinModule extends GxtUserGinModule {
	protected void configure() {
		super.configure();
		
		bind(UserDesktop.class).to(FlangUserDesktop.class);
		
		bind(RequestFactory.class).to(ApplicationRequestFactory.class);
		Binder.bind(binder());
	}
	
	@Provides
	@Singleton
	public ApplicationRequestFactory createRequestFactory(GwtDataRequestTransport transport) {
		ApplicationRequestFactory rf = GWT.create(ApplicationRequestFactory.class);
		rf.initialize(new SimpleEventBus(), transport);
		return rf;
	}
	
	@Provides
	@Singleton
	public UiBuilderMenuGroup uiBuilderMenuGroup(Menu menu, UiMessages messages) {
		MenuGroup menuGroup = menu.addMenuGroup();
		menuGroup.setText(messages.manage());
		UiBuilderMenuGroup d = new UiBuilderMenuGroup();
		d.setDelegate(menuGroup);
		return d;
	}
	
	@Provides
	@Singleton
	public Menu menu(UserDesktop userDesktop) {
		return userDesktop.menu();
	}
	
	@Provides
	@Singleton
	public Workspace workspace(UserDesktop userDesktop) {
		return userDesktop.workspace();
	}
	
	
}